package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.setWaterMarkBean;
import com.ymatou.iapi.godmch.service.setWaterMarkCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.model.godmch.mch_configExample.Criteria;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
/**
*设置商户水印开关
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setWaterMark{
	private static setWaterMarkBean bean;
	private static setWaterMarkCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商户水印开关");
	}

	@Before
	public void caseUp() {
		bean=new setWaterMarkBean();
		call=new setWaterMarkCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws InterruptedException
	{
		mch_configWapper wapper=new mch_configWapper();
		mch_configExample example=new mch_configExample();
		Criteria criteria=example.createCriteria();
		criteria.andMchIdEqualTo(bean.getMchId());
		criteria.andWaterMarkEqualTo(bean.getWaterMark());
		criteria.andAgentWaterMarkEqualTo(bean.getAgentWaterMark());
	    List<mch_config> DB_infos=wapper.selectByExample(example);
	    
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals(1, DB_infos.size(), "验证数据库新增的条数");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_001() {
		Logger.start(true,"正例-设置商户水印开关-渠道-我的代理商商品、自采商品打开");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setMchId(mchId);
			bean.setWaterMark(true);
			bean.setAgentWaterMark(true);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_002() {
		Logger.start(true,"正例-设置商户水印开关-渠道-自采商品关闭、我的代理商商品打开");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setMchId(mchId);
			bean.setWaterMark(false);
			bean.setAgentWaterMark(true);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_003() {
		Logger.start(true,"正例-设置商户水印开关-渠道-自采商品打开、我的代理商商品关闭");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setMchId(mchId);
			bean.setWaterMark(true);
			bean.setAgentWaterMark(false);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_004() {
		Logger.start(true,"正例-设置商户水印开关-代理-自采商品、我的代理商商品打开");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean2);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));

			bean.setMchId(agentid);
			bean.setWaterMark(true);
			bean.setAgentWaterMark(false);
			
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_005() {
		Logger.start(true,"正例-设置商户水印开关-自采商品、我的代理商商品关闭");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setMchId(mchId);
			bean.setWaterMark(false);
			bean.setAgentWaterMark(false);
			call.setData(bean);
			call.callService();				
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_006() {
		Logger.start(true,"正例-设置商户水印开关-原来是打开-现在打开");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setMchId(mchId);
			bean.setWaterMark(true);
			bean.setAgentWaterMark(true);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_007() {
		Logger.start(true,"正例-设置商户水印开关-原来是关闭-现在关闭");
		try {
			
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setMchId(mchId);
			bean.setWaterMark(false);
			bean.setAgentWaterMark(false);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setWaterMark_008() {
		Logger.start(true,"正例-设置商户水印开关-商户mchid为空");
		try {
			
			//bean.setMchId(mchId);
			bean.setWaterMark(true);
			bean.setAgentWaterMark(true);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}